package com.my.feign;

import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentService;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("feign")
public class TestFeign implements ITestFeign {

    @Autowired
    private PaymentService paymentService;

    @Override
//   ITestFeign interface 中定义了getmapping以后这里就不需要了 但是controller上有mapping路径的话不行
    @GetMapping(value = "/payment/findOne")
    public R<Payment> findOne(@RequestParam Long id) {
        return R.ok(paymentService.getPaymentById(id));
    }

    @Override
    @GetMapping(value = "/payment/timeOut")
    public R timeOut() {
        try {
            TimeUnit.SECONDS.sleep(3);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        return R.ok("延时3秒返回");
    }


}
